PROJECT_NAME:=dataGen
COMPER:=aarch64-linux-gnu-
CC = $(COMPER)gcc
CXX = $(COMPER)g++
LD=$(COMPER)g++


OBJDIR_RELEASE := ../objects
CPP_SRC_FILE:= $(shell find . -iname "*.cpp")
C_SRC_FILE:= $(shell find . -iname "*.c")
CPP_OBJECTS:= $(patsubst ./%.cpp, $(OBJDIR_RELEASE)/%.o, $(CPP_SRC_FILE))
C_OBJECTS:= $(patsubst ./%.c, $(OBJDIR_RELEASE)/%.o, $(C_SRC_FILE))
DIR_OBJECTS := $(dir $(CPP_OBJECTS))
DIR_OBJECTS += $(dir $(C_OBJECTS))


OBJ_RELEASE:=$(CPP_OBJECTS)
OBJ_RELEASE+=$(C_OBJECTS)


CFLAGS=-Wall -fexceptions
CXXFLAGS=-std=c++17 -Wall -fexceptions
INC_RELEASE=

ifeq ($(COMPER), )
LIB=/usr/local/lib/libOpenXLSX.a
LIB+=/usr/local/lib/libzlog.a
LIB+=/usr/local/lib/libxxhash.a
LIB+=/usr/local/lib/libredis++.a
LIB+=/usr/local/lib/libhiredis.a
else 
LIB+=/home/ubuntu/CrossCompile/aarch64/lib/libOpenXLSX.a
LIB+=/home/ubuntu/CrossCompile/aarch64/lib/libzlog.a
LIB+=/home/ubuntu/CrossCompile/aarch64/lib/libxxhash.a
LIB+=/usr/aarch64-linux-gnu/lib/libredis++.a
LIB+=/home/ubuntu/CrossCompile/aarch64/lib/libhiredis.a
INC_RELEASE+=-I/home/ubuntu/CrossCompile/aarch64/include
endif



LIB+=-lpthread


OUT_DIR_RELEASE=../release
OUT_RELEASE = $(OUT_DIR_RELEASE)/$(PROJECT_NAME)


all: before_release release
	@echo "\033[32;49;1m===[ $(PROJECT_NAME) Program Running ]=== \033[39;49;0m"
	scp ../release/dataGen em1000:datalink/


.PHONY: clean all before_release
clean: clean_release


before_release:
	$(foreach dir, $(DIR_OBJECTS),$(shell mkdir -p $(dir)))
	mkdir -p $(OUT_DIR_RELEASE)


after_release:


release: out_release after_release


out_release: $(OBJ_RELEASE)
	$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $^  $(LDFLAGS_RELEASE) $(LIB_RELEASE) $(LIB)
	@echo "\033[32;49;1m===[ Compile Complete ]=== \033[39;49;0m"


# $(OBJDIR_RELEASE)/main.o: main.cpp
# 	$(CXX) $(CXXFLAGS) $(INC_RELEASE) -c $< -o $@
$(OBJDIR_RELEASE)/%.o: %.cpp 
	$(CXX) $(CXXFLAGS) $(CXXFLAGS_RELEASE) $(INC_RELEASE) -c $< -o $@


$(OBJDIR_RELEASE)/%.o: %.c %h
	$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c $< -o $@
clean_release:
	rm -rf $(OUT_DIR_RELEASE) $(OBJDIR_RELEASE)
